2008/01/31

Recent entries from same category

  1. どこでもスターグリースモンキーは開発者を殺す?
  2. はてなには、既存ユーザを無視したサービスを作って欲しい
  3. はてなドメインでなくても、モバイル端末から「はてなスター」を付けてもらうハック
  4. はてなスクリーンショットに微笑む
  5. はてなのお気に入りユーザを一覧してみる

擬似GM_xmlhttpRequestを使ってたので、はてなリソースしか動いてなかった。
擬似GM_xmlhttpRequestでは、はてなスターの場合だけJSONで動かすようにしたので、きっと行けると思う。
JSONデータから文字列に戻す部分はこれを使わせて頂いた。
前とそれほど変わらないけど、unsafeWindowの宣言場所を上にもってったので前回のような簡単なパッチの当て方は出来なくなった。

--- HatenaStarEverywhere.user.js.orig   Mon Oct 01 10:37:41 2007
+++ HatenaStarEverywhere.user.js    Fri Oct 05 23:08:10 2007
@@ -92,6 +92,9 @@
     ensure(window.Hatena, 'Star');
 }
 
+if (typeof unsafeWindow == "undefined") {
+    var unsafeWindow = window;
+}
 if (typeof unsafeWindow.Hatena == 'undefined'
         || typeof unsafeWindow.Hatena.Star == 'undefined'
         || !unsafeWindow.Hatena.Star.loaded) {
@@ -138,4 +141,137 @@
             GM_setValue('configExpire', '');
         }
     });
+}
+
+if (typeof(GM_setValue) != 'function') {
+  function GM_setValue(key, value) {
+    document.cookie = [
+      name, '=', escape(value),
+      ';expires=', (new Date(new Date() + 365 * 1000 * 60 * 60 * 24)).toGMTString()
+    ].join('');
+  }
+}
+if (typeof(GM_getValue) != 'function') {
+  function GM_getValue(key) {
+    var r = new RegExp('/' + name + '=([^;]*)/'), m;
+    if (m = document.cookie.match(r)) return unescape(m[1]);
+    return null;
+  }
+}
+if (typeof(GM_xmlhttpRequest) != 'function') {
+  var GM_xmlhttpRequest_Data = null;
+  function GM_xmlhttpRequest_Handler(data) {
+     GM_xmlhttpRequest_Data = toJsonString(data);
+  }
+  function GM_xmlhttpRequest(opt) {
+    if (opt.url == 'http://s.hatena.ne.jp/siteconfig.json') {
+       var s = document.createElement('script');
+       s.charset = 'utf-8';
+       s.onload = function(e) {
+          s.responseText = GM_xmlhttpRequest_Data;
+          opt.onload(s);
+         GM_xmlhttpRequest_Data = null;
+       }
+       s.src = opt.url + '?callback=GM_xmlhttpRequest_Handler';
+       document.body.appendChild(s);
+   }
+    var x=new XMLHttpRequest();
+    x.onreadystatechange=function() {
+      switch(x.readyState) {
+        case 4:
+          opt.onload(x);
+          break;
+      }
+    };
+    x.open(opt.method,opt.url,true);
+    x.setRequestHeader('Content-Type',opt.mime);
+    x.send(null);
+  }
+}
+
+/*
+ * include http://code.google.com/p/trimpath/wiki/JsonLibrary
+ * with few modify for opera.
+ */
+
+/*
+Copyright (c) 2002 JSON.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+The Software shall be used for Good, not Evil.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+function toJsonString(arg) {
+    return toJsonStringArray(arg).join('');
+}
+
+function toJsonStringArray(arg, out) {
+    out = out || new Array();
+    var u; // undefined
+
+    switch (typeof arg) {
+    case 'object':
+        if (arg) {
+            if (arg.constructor == Array) {
+                out.push('[');
+                for (var i = 0; i < arg.length; ++i) {
+                    if (i > 0)
+                        out.push(',\n');
+                    toJsonStringArray(arg[i], out);
+                }
+                out.push(']');
+                return out;
+            } else if (typeof arg.toString != 'undefined') {
+                out.push('{');
+                var first = true;
+                for (var i in arg) {
+                    var curr = out.length; // Record position to allow undo when arg[i] is undefined.
+                    if (!first)
+                        out.push(',\n');
+                    toJsonStringArray(i, out);
+                    out.push(':');                    
+                    toJsonStringArray(arg[i], out);
+                    if (out[out.length - 1] == u)
+                        out.splice(curr, out.length - curr);
+                    else
+                        first = false;
+                }
+                out.push('}');
+                return out;
+            }
+            return out;
+        }
+        out.push('null');
+        return out;
+    case 'unknown':
+    case 'undefined':
+    case 'function':
+        out.push(u);
+        return out;
+    case 'string':
+        out.push('"')
+        out.push(arg.replace(/(["\\])/g, '\\$1').replace(/\r/g, '').replace(/\n/g, '\\n'));
+        out.push('"');
+        return out;
+    default:
+        out.push(String(arg));
+        return out;
+    }
 }


追記
[はてな][ネット]Twitterとはてなスターは相性がいい」こちらで紹介して頂きました。
一応、私の手元で動いている物をアップします。
はてな事務局さん、問題があればご連絡下さい。
HatenaStarEverywhere.user.js
Posted at by